import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Vector;

/**
 * Holds all relevant documents for a query
 * @author daniel
 *
 */
public class RelevanceReference {
	Vector<Vector<String>> results = new Vector<Vector<String>>();

	public RelevanceReference(String path) {
		results = new Vector<Vector<String>>();
		String whitStr = "^([\\s.,;:\\-\\(\\)\\!\\?'\"])+$";
		BufferedReader reader = null;
		String line = "";
		try {
			reader = new BufferedReader(new FileReader(path));
			while ((line = reader.readLine()) != null)
			{
				if(!line.matches(whitStr) && line.length() > 0)
				{
					Vector<String> result = new Vector<String>();
					String [] tokens = line.split("[\\s.,;:\\-\\(\\)\\!\\?'\"]");
					for(int i=1; i<tokens.length; i++)		// skip first element
					{
						if(!tokens[i].matches(whitStr) && tokens[i].length() > 0)
						{
							result.add("doc"+tokens[i]);
						}
					}
					results.add(result);
				}
			}
			reader.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public boolean isRelevant(String doc, int query) {
		if(results.get(query)!=null) {
			return results.get(query).contains(doc);
		}
		else {
			return false;
		}
	}

	/**
	 * Returns the number of relevant docs for a query
	 */
	public int relevantCountForQuery(int query) {
		if(results.get(query)!=null) {
			return results.get(query).size();
		}
		else {
			return 0;
		}
	}

}
